# -*- coding: utf-8 -*-

from ..base_client import BaseClient
from common_sdk.system.sys_env import get_env


class OrderClient(BaseClient):
    resource = "order"

    def __init__(self):
        super().__init__()
        self.domain = get_env("TRADE_SERVICE_DOMAIN")

    def create_order(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("create"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def get_order(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("get"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def update_order(self, builder):
        result = self.do_http_post_only_data_only_data(
            self.__generate_uri("update"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def list_order(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("list"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def delete_order(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("delete"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def __generate_uri(self, operation):
        uri = f"{self.resource}/{operation}"
        return uri